<?
include_once 'library.php';
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<title>SK Communications A11Y Score Board</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!-- Bootstarap Version -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
<link type="text/css" rel="stylesheet" href="bootstrap/css/bootstrap.css" />
<!-- //Bootstarap Version -->
<script type="text/javascript" src="js/common.js"></script>
<!-- Basic Style -->
<link type="text/css" rel="stylesheet" href="css/style.css" />
<!-- //Basic Style -->
</head>
<body>
<?
$table_name = "test_result";
$select_array = array("*");

/* 한 페이지당 게시물 수 */
$pageRow = 20;

/* 중복 URL 체크박스 */
$uniqueCheck = $_GET['unique_check'];

/* 페이징 시작 값 */
if(!$_GET['page']){
	$cPage = "1";
	$pageStart = $cPage - 1;
}else{
	$cPage = $_GET['page'];
	$pageStart = ($cPage - 1) * $pageRow;
}

$limit = " LIMIT $pageStart, $pageRow";

/* 검색쿼리 처리 */
if($_GET['search_query'] != ""){
	$search_query = $_GET['search_query'];
	
	/* http scheme check */
	if(!strstr($search_query,"http://") && !strstr($search_query,"https://")){
		$search_query = "http://".$search_query;
	}
	
	$search_condition = "title LIKE '%$search_query%' OR url LIKE '$search_query%'";
	$condition = "$search_condition ORDER BY timestamp desc";
	$totalCount = count(selectDB($table_name, $select_array, $condition));
	$site_title = "<a href=\"$search_query\" target=\"_blank\">$search_query</a>";
}else{
	$condition = "1=1 ORDER BY timestamp desc";
	$resultCount = selectDB($table_name, $column_arr, $condition);
	$totalCount = selectDB($table_name, array("count(*)"), "1=1");
	$totalCount = $totalCount[0][0];
	$site_title = "전체 서비스";
}

/* 중복 URL 제거 */
if($uniqueCheck){
	$result = selectDBQ("SELECT * FROM (SELECT * FROM $table_name WHERE $condition ) AS pseudoTable GROUP BY pseudoTable.url ORDER BY pseudoTable.timestamp DESC $limit");
	$totalCount = count(selectDBQ("SELECT * FROM (SELECT * FROM $table_name WHERE $condition ) AS pseudoTable GROUP BY pseudoTable.url ORDER BY pseudoTable.timestamp DESC"));
	$score_sum = selectDBQ("SELECT SUM(scoreTable.score) FROM (SELECT * FROM (SELECT * FROM $table_name WHERE $condition ) AS pseudoTable GROUP BY pseudoTable.url ORDER BY pseudoTable.timestamp DESC) AS scoreTable");
}else{
	$result = selectDB($table_name, $select_array, $condition.$limit);
	$score_sum = selectDB($table_name, array('sum(score)'), $condition);
}

/* 서비스별 평균 점수 */
$score_sum = $score_sum[0][0];
$a11y_score = number_format($score_sum / $totalCount,2);

?>
<div id="wrap">
	<div class="contents">
		<div class="navWrap">
			<h3>SK Communications A11Y</h2></h3>
			<div class="navbar">
				<div class="navbar-inner">
					<div class="container">
						<ul class="nav">
							<li><a href="/tools/a11y/">홈</a></li>
							<li><a href="/tools/a11y/install.html">설치 가이드 &amp; 다운로드</a></li>
							<li class="active"><a href="/tools/a11y/score_check.php">점수 집계표</a></li>
							<li><a href="/tools/a11y/service.php">서비스별 평균 점수표</a></li>
							<li><a href="/tools/a11y/rank.php">사내 측정 횟수표</a></li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<h3 class="score_title"><?=$site_title?> 평균점수 <span class="num"><?=$a11y_score?>점</span></h3>
		<table class="table table-bordered" summary="사내 서비스의 웹접근성 테스트 결과입니다. 순번, 타이틀, URL, 점수, 시간순의 5열 10행 표입니다.">
			<caption>SK Communications 사내 웹접근성 테스트 결과표</caption>
			<colgroup>
				<col scope="col">
				<col scope="col">
				<col scope="col">
				<col scope="col">
				<col scope="col">
			</colgroup>
			<thead>
				<tr class="navbar-inner">
					<th>No</th>
					<th>Title</th>
					<th>URL</th>
					<th>Score</th>
					<th>Check Time</th>
				</tr>
			</thead>
			<tfoot></tfoot>
			<tbody>
			<?
				$no = $totalCount - $pageStart;
				for($i=0; $i < count($result); $i++){
					$url = $result[$i]['url'];
					$title = $result[$i]['title'];
					$score = $result[$i]['score'];
					$timestamp = $result[$i]['timestamp'];
					
					$checkdate = date("Y-m-d", $timestamp);
					$checktime = date("H:i:s", $timestamp);
					
					if($score >= 95){
						$trClass = "success";
					}elseif($score >= 80){
						$trClass = "warning";
					}else {
						$trClass = "error";
					}
					
					
					echo '<tr class="'.$trClass.'"><td>'.$no.'</td><td>'.$title.'</td><td><a href="'.$url.'" title="'.$url.'" target="_blank">'.$url.'</a></td><td class="score">'.$score.'점</td><td class="time">'.$checkdate.'&nbsp;'.$checktime.'</td></tr>';
					$no--;
				}
			?>
			</tbody>
		</table>
		<form action="<?=$PHP_SELF?>" method="GET" class="form-search">
			<div class="input-append search_wrap">
				<div class="ucWrap" data-toggle="tooltip" tabindex="0">
					<input type="checkbox" name="unique_check" id="unique_check" <? if($uniqueCheck) echo 'checked=checked'; ?> /><label for="unique_check">중복 URL 제거</label>
				</div>
				<div class="keywordWrap">
					<label for="search_query">검색어</label>
					<input type="text" name="search_query" id="search_query" class="search-query" value="<?=$search_query?>" placeholder="전체목록은 빈 값 검색">
					<button type="submit" class="btn btn-info" title="검색"><i class="icon-search icon-white"></i></button>
				</div>
			</div>
			
		</form>
		<? paging($totalCount, $cPage, $pageRow); ?>
		<ul>
			<li><i class="icon icon-ok"></i> &nbsp; 95점 이상은 녹색, 80점 이상은 노란색, 그 이하는 빨간색으로 표시됩니다.</li>
			<li><i class="icon icon-ok"></i> &nbsp; 검색어 입력시 <strong>"http://", "https://"</strong>를 입력하셔야 정확한 검색결과를 제공합니다. 미 입력시 <strong>"http://"</strong>가 기본입니다.</li>
			<li><i class="icon icon-ok"></i> &nbsp; 측정 점수 및 평균 점수는 접근성 확보의 절대적 판단기준이 되지 않습니다.</li>
		</ul>
	<div>
</div>
<div class="footer">2013. SK Communications | UI Dev Team</div>
<script type="text/javascript">
$('.ucWrap').tooltip(
	{
		trigger:'focus',
		title: '중복된 URL을 제거하고 <br/>가장 최신 검사 결과만 보여줍니다.',
		placement: 'top'
	}
);
</script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-39065309-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</body>
</html>
